package com.share.netty.splitpacket;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

/**
 * @author caifan
 * @createTime 2020/5/5
 * @desc:
 */
public class PacketServerHandler extends SimpleChannelInboundHandler<MyMessageProtocol> {

    private int count;

    @Override
    public void channelRead0(ChannelHandlerContext ctx, MyMessageProtocol msg) {
        /*ByteBuf byteBuf = (ByteBuf) msg;
        System.out.println("服务端读取数据：" + byteBuf.toString(CharsetUtil.UTF_8) + "\n");*/
        System.out.println("====服务端接收到消息如下====");
        System.out.println("长度=" + msg.getLen());
        System.out.println("内容=" + new String(msg.getContent(), CharsetUtil.UTF_8));

        System.out.println("服务端接收到消息包数量=" + (++this.count));
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }
}
